package com.bolingcavalry.crm.minio.controller;

import com.bolingcavalry.crm.minio.service.MinioService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/api/upload")
public class UploadController {

    @Autowired
    private MinioService minioService;

    //上传图片到minio
    @PostMapping("/upImage")
    public String uploadImage(@RequestParam("file") MultipartFile file) throws Exception {
        return minioService.uploadFile(file);
    }

    //获取图片的url
    @PostMapping("/getImage")
    public List<String> getImageUrl(@RequestBody List<String> objectNames) {
        return minioService.getPresignedUrl(objectNames);
    }

    //根据图片的filename删除图片
    @PostMapping("/deleteImage")
    public String deleteImage(@RequestBody String objectName) throws Exception {
        return minioService.deleteFile(objectName);
    }
}